package agentspeakide.editors;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;

public class ASLPlanScanner extends RuleBasedScanner {
	
	public ASLPlanScanner(ColorManager manager) {
		
		IToken string =
			new Token(
				new TextAttribute(manager.getColor(IASLColorConstants.STRING)));
		
		IToken aslWord =
				new Token(
					new TextAttribute(manager.getColor(IASLColorConstants.PLAN)));
		
		IToken aslBoolean =
				new Token(
					new TextAttribute(manager.getColor(IASLColorConstants.BOOLEAN)));
		
		IToken aslKeywords =
				new Token(
					new TextAttribute(manager.getColor(IASLColorConstants.KEYWORDS)));

		IRule[] rules = new IRule[4];

		//Regra de string
		rules[0] = new SingleLineRule("\"", "\"", string, '\\');
		//Regra de string
		rules[1] = new SingleLineRule("'", "'", string, '\\');
		// Add generic whitespace rule.
		rules[2] = new WhitespaceRule(new ASLWhitespaceDetector());
		
		//Regra de palavras default, true e false
		WordRule wordRule= new WordRule(new ASLWordDetector(), aslWord);
		wordRule.addWord("true", aslBoolean);
		wordRule.addWord("false", aslBoolean);
		
		//Regra para cada palavra chave
		for(int i=0; i < ASLContentAssistProcessor.KEYWORDS.length; i++)
		{
			wordRule.addWord(ASLContentAssistProcessor.KEYWORDS[i], aslKeywords);
		}
		
		rules[3] = wordRule;
		
		setRules(rules);
	}
}
